

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const app=getApp();
function msg(res){
	 if(res.data.code==1){
	 		 wx.showToast({
         icon:'none',
	 		   title: res.data.msg
	 		 })
	 	 }
}

function navigateTo(options, permission = true) {
   if (permission && !wx.getStorageSync('token')) {
		wx.navigateTo({
		  url:'/pages/login/auth/auth'
		})
	}else {
    wx.navigateTo(options);
  }
}

function isopenblue(callback){
  wx.openBluetoothAdapter({
    success (res) {
      wx.getBluetoothAdapterState({
        success (res) {
          if(res.available==false){
            // wx.showToast({
            //   icon:'none',
            //   title: '蓝牙未开启！',
            // })         
            callback({errMsg: '蓝牙未开启！'});
          }else{
            callback(null);
          }
        },
        fail(res){
          callback(false);
      }
    })
    },
    fail(err) {
     callback(err);
    }
})

}



function removeNull(obj){
    for(let i in obj){
      if(obj[i]==null){
        obj[i]=''
      }
    }
    return obj;
}

function toauth(){
	if (!app.globalData.auth) {
		wx.navigateTo({
			url: '/pages/login/auth/auth',
		})
		return;
	}
}


module.exports = {
  formatTime,
  msg,
  isopenblue,
  navigateTo,
  removeNull,
  toauth
}






